package com.qaml.mes.device.controller;


import com.earth.output.OutputMessage;
import com.earth.page.PageResponse;
import com.qaml.mes.device.api.CheckUpkeepInfoService;
import com.qaml.mes.device.dto.eqp.CheckUpkeepInfoDTO;
import com.qaml.mes.device.dto.eqp.CheckUpkeepInfoIdDTO;
import com.qaml.mes.device.dto.eqp.CheckUpkeepInfoListDTO;
import com.qaml.mes.device.vo.eqp.CheckUpkeepInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 检保信息表 前端控制器
 * </p>
 *
 * @author leikai
 * @since 2024-02-27
 */
@Api(tags = "检保项目维护")
@RestController
@RequestMapping("/checkUpkeepInfo")
public class CheckUpkeepInfoController {

    @Resource
    private CheckUpkeepInfoService checkUpkeepInfoService;

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "检保信息-新增修改(Web)", notes = "检保信息-新增修改")
    public OutputMessage<String> saveOrUpdate(@RequestBody @Validated CheckUpkeepInfoDTO checkUpkeepInfoDTO) {
        checkUpkeepInfoService.saveOrUpdate(checkUpkeepInfoDTO);
        return OutputMessage.success("保存成功");
    }

    /**
     * 删除检保项目信息 --逻辑删除
     *
     * @param checkUpkeepIdDTO
     * @return
     */
    @PostMapping("/deleteByCheckUpkeepId")
    @ApiOperation(value = "检保项目信息-删除(Web)", notes = "检保项目信息-删除")
    public Boolean delete(@RequestBody @Validated CheckUpkeepInfoIdDTO checkUpkeepIdDTO) {
        return checkUpkeepInfoService.deleteByCheckUpkeepId(checkUpkeepIdDTO.getId());
    }

    /**
     * 获取设备详情信息
     *
     * @param checkUpkeepId
     * @return
     */
    @GetMapping("/getByCheckUpkeepId")
    @ApiOperation(value = "检保项目信息-详情-根据检保项目编号获取(Web)", notes = "检保项目信息-详情-根据检保项目编号获取")
    public OutputMessage<CheckUpkeepInfoVO> getByCheckUpkeepId(@RequestParam("checkUpkeepId") String checkUpkeepId) {
        return OutputMessage.success(checkUpkeepInfoService.getByCheckUpkeepId(checkUpkeepId));
    }

    /**
     * 获取设备列表信息(分页)
     */
    @PostMapping("/checkUpkeepInfoList")
    @ApiOperation(value = "检保项目信息-列表-根据id获取(Web)")
    public PageResponse<CheckUpkeepInfoVO> list(@RequestBody CheckUpkeepInfoListDTO checkUpkeepInfoListDTO) {
        return checkUpkeepInfoService.getCheckUpkeepInfoVOList(checkUpkeepInfoListDTO);

    }


    @PostMapping("/enableEqp")
    @ApiOperation(value = "检保信息-启用(Web)", notes = "检保信息-启用")
    public OutputMessage<String> enableEqp(@RequestBody @Validated CheckUpkeepInfoIdDTO checkUpkeepIdDTO) {
        checkUpkeepInfoService.enableEqp(checkUpkeepIdDTO.getId());
        return OutputMessage.success("检保信息启用成功！");
    }

    @PostMapping("/disableEqp")
    @ApiOperation(value = "检保信息-禁用(Web)", notes = "检保信息-禁用")
    public OutputMessage<String> disableEqp(@RequestBody @Validated CheckUpkeepInfoIdDTO checkUpkeepIdDTO) {
        checkUpkeepInfoService.disableEqp(checkUpkeepIdDTO.getId());
        return OutputMessage.success("检保信息禁用成功！");
    }
}
